package com.hf.healthy_life.service.ServiceImpl;

import com.hf.healthy_life.mapper.UserMapper;
import com.hf.healthy_life.pojo.User;
import com.hf.healthy_life.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl  implements UserService {
    @Autowired
    private UserMapper userMapper;
    /*用户登录*/
    @Override
    public User login(String username, String password) {
     User user =  userMapper.login(username,password);
     if (user == null)
         throw new RuntimeException("用户名或密码错误");
     return user;
    }
    /*用户注册*/

    @Override
    public int register(String username, String phone, String password) {
        User user = new User();
        user.setUserName(username);
        user.setPhone(phone);
        user.setPassword(password);
        return userMapper.insert(user);
    }
    /*查询用户信息*/
    @Override
    public User getUserInfo(Long userId) {
        return userMapper.selectById(userId);
    }
    /*修改密码*/

    @Override
    public int editPassword(User user) {
        return userMapper.updateById(user);
    }

    @Override
    public int updateUserInfo(User user) {
        return userMapper.updateById(user);
    }
}
